<template>
<view v-if="Object.keys(info).length" class="main">
  <nav-bar title="招募详情" />
  <view class="flex_r info">
    <view :class="['status', info.status == 1 &&  'waiting' ,info.status == 3 && 'audit']">
       {{ info.status === 1 ? '审核中' : info.status === 2 ? '审核通过' : '已驳回'}}
    </view>
   <view class="cover">
      <image class="auth_icon" :src="`https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/auth_icon.png`" alt="" />
      <image mode="aspectFill" class="profile_photo"
        :src="info.headOssUrl || 'https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/avatar_default.png'"></image>
    </view>
    <view class="flex1">
      <view class="userName">{{ info.userName }}<text v-if="info.entInfo" class="userName_desc">【企业招募】</text></view>
      <view v-if="info.entInfo" class="info_txt">{{ info.entInfo.entName }} - {{ info.entInfo.staffPost }}</view>
      <view v-if="info.userOccIdsName" class="info_type">{{ info.userOccIdsName.replace(/,/g, ' | ')}}</view>
    </view>
    <view class="address flex_a_c">
      {{ info.userProvinceName }}<template v-if="info.userCityName">·{{info.userCityName}}</template><image class="address_icon" src="https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/address_icon.png"></image>
    </view>
  </view>
  <view v-if="info.status == 3" class="refuse mt-2">
    拒绝原因：{{ info.failReason }}
  </view>
  <view class="requirement">
   <view class="requirement_title flex_b_c pr-30">
      招募{{ info.occupationIdsName }}
      <view class="price">
        <template v-if="info.amountType === 4">面议</template>
        <template v-else>
          {{ info.lowAmount }}-{{ info.highAmount }}K
          <text v-if="amountTypeList.find(({ id }) => id === info.amountType)" class="price_desc">（{{ amountTypeList.find(({ id }) => id === info.amountType).dicName }}）</text>
        </template>
      </view>
    </view>
    <view class="requirement_cont">
      <view>招聘人数：{{ info.peopleNum }}</view>
      <view>经验要求：{{ info.experienceFlag ? '有' : '无' }}</view>
      <view class="flex_r">工作地址：<text class="flex1">{{ info.address }}</text></view>
      <view v-if="info.startTime">工作周期：{{ info.startTime.replace(/-/g, '/') }} - {{ info.endTime.replace(/-/g, '/') }}</view>
    </view>
    <view class="flex_b_c requirement_opt">
      <viue>{{ info.createTime }} 发布</viue>
      <view v-if="info.status === 2" class="flex_a_c pr-30">
        <image class="requirement_icon" src="https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/rep_play_icon.png"></image>
        <text>{{ info.seeNum }}</text>
        <image class="requirement_icon ml-22" src="https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/rep_collect_icon.png"></image>
        <text>{{ info.collectNum }}</text>
      </view>
    </view>
    <image class="requirement_img" mode="aspectFill" :src="info.coverOssUrl"></image>
  </view>
  <view class="desc">
    <view class="desc_title">招募要求</view>
    <view class="pl-7">{{ info.requirement }}</view>
  </view>
  <view v-if="info.deliUserList && info.deliUserList.length" class="delivery">
    <view class="flex_b_c mb-11 pr-30">
      <view class="delivery_title">已投递<text class="delivery_num">（{{ info.deliveryNum }}人）</text></view>
      <navigator v-if="info.deliveryNum" class="delivert_more" :url="`/pages/ipElite/deliveryUserList?id=${info.id}&self=true`" hover-class="none">
        查看全部 >
      </navigator>
    </view>
    <view class="flex_r flex_wrap pr-20">
      <image mode="aspectFill" class="delivery_icon mb-21" :style="{ zIndex: idx }" v-for="(item, idx) in info.deliUserList" :key="idx" :src="item.headOssUrl"></image>
    </view>
  </view>
  <view :class="['fixed_footer flex_a_c flex_b_c']">
    <view class="btns flex1 primary" @click="onDel">删除</view>
    <navigator :url="`/pages/ipElite/publishRecruit?id=${info.id}`" hover-class="none" v-if="info.status !== 1" class="btns flex1 normal ml-20">
      修改
    </navigator>
    <view v-if="info.status === 2" class="btns confirm flex1 ml-20" @click="onShelf">{{ info.shelfStatus ? '下架' : '上架' }}</view>
  </view>
</view>
<van-dialog id="van-dialog" cancel-button-color="#999999" confirm-button-color="#00B277" />
</template>
<script setup>
import { ref, reactive } from 'vue'
import { recruitDetail } from "@/api/ipElite"
import Dialog from '/wxcomponents/vant/dialog/dialog';
import { deleteRecruit, recruitBatchShelf } from '@/api/center'
import { onLoad } from '@dcloudio/uni-app'
let amountTypeList = [{ id: 1, dicName: '日薪' }, { id: 2, dicName: '月薪' }, { id: 3, dicName: '每单' }, { id: 4, dicName: '面议' }]
let info = reactive({})
onLoad(({ id }) => {
  info.id = id
  fnGet(id)
  // getAgentData(id)
})
let fnGet = async (id) => {
  const { code, data } = await recruitDetail({ id })
  if (code === 200) {
    Object.keys(data).forEach(key => info[key] = data[key])  // 基本信息
    // fnRecomList(id)
  }
}
let onDel = () => {
  Dialog.alert({
    title: '温馨提示',
    cancelButtonColor: '#999999',
    confirmButtonColor: '#00B277',
    cancelButtonText: '再想想',
    showCancelButton: true,
    closeOnClickOverlay: true,
    confirmButtonText: '删除',
    message: '您确定要删除该招募？',
  }).then(async () => {
    console.log(info.id)
    const { code, data } = await deleteRecruit({ id: info.id })
    if (code === 200) {
      uni.redirectTo({
        url: '/pages/center/ipElite/recruitManage'
      })
    }
    // on close
  }).catch(() => {
    
  });
}
// let onBack = () => {
//   uni.redirectTo({
//     url: '/pages/center/ipElite/recruitManage'
//   })

// }
let onShelf = async () => {
  let authFlag = storage.getStorage('info').authFlag
  if (authFlag !== 2) {
    isShow.value = true
    Dialog.alert({
      title: '温馨提示',
      cancelButtonColor: '#999999',
      confirmButtonColor: '#00B277',
      cancelButtonText: '再想想',
      showCancelButton: true,
      closeOnClickOverlay: true,
      confirmButtonText: '去实名',
      message: '您需要实名后才可上下架招募?',
    }).then(async () => {
      console.log(info.id)
      uni.redirectTo({
        url: '/pages/center/auth/index'
      })
      // on close
    }).catch(() => {
      
    });
    return false
  }
  let shelfStatus = info.shelfStatus ? 0 :1
  const { code, data } = await recruitBatchShelf({ ids: [info.id], shelfStatus })
  if (code === 200) {
    info.shelfStatus = shelfStatus
    uni.showToast({
      title: `${shelfStatus ? '上架' : '下架'}成功`,
      icon: 'none'
    })
  }
}
</script>
<style lang="scss" scoped src="/static/style/ipElite/recruitDetail.scss"></style>

<style lang="scss" scoped>
.main {
  padding-bottom: calc(175rpx + constant(safe-area-inset-bottom));
  padding-bottom: calc(175rpx + env(safe-area-inset-bottom));
  .status {
    position: absolute;
    top: 0;
    right: 0;
    width: 127rpx;
    height: 58rpx;
    background: #00B277;
    border-radius: 29rpx 0rpx 0rpx 29rpx;
    text-align: center;
    font-weight: 500;
    font-size: 26rpx;
    color: #FFFFFF;
    line-height: 58rpx;
    &.waiting {
      background: #EDA331;
    }
    &.audit {
      background: #CC0000;
    }
  }
  .refuse {
    font-size: 26rpx;
    padding: 30rpx;
    color: #666666;
    line-height: 42rpx;
    background: #fff;
  }
}
</style>